import { logUnderline, logTitle, logSubTitle, log } from "../utils/index";
import { CmpA } from "./6-外部枚举";

function use() {
    logTitle("六、枚举");
    logSubTitle("1、数字枚举（自加）");
    logSubTitle("2、字符枚举（必须全是字符）");
    logSubTitle("3、异构枚举（极其不推荐）");
    logSubTitle("4、取值");

    enum NumberEnum {
        bee,
        lion,
        tiger,
    }

    enum StringberEnum {
        bee = "bee",
        lion = "lion",
        tiger = "tiger",
    }

    // 字符数字混用，且字符在最后
    enum MixinEnum {
        bee,
        lion,
        tiger = "tiger",
    }

    // 取值
    // 同值只取最后的那个
    enum DemoEnum {
        a = 1,
        b = 2,
        c = b | a,
        d = "123".length,
        e = 1 >> 2,
    }
    console.log(1 | 2);
    log(DemoEnum);

    logSubTitle("5、const 枚举");
    logSubTitle("6、外部枚举");

    // 只能用常量，不能用计算属性
    let str = "123";
    const enum ConstEnum {
        a,
        // b = 1 + str.length, // 报错
        c,
    }

    // 外部枚举
    // https://juejin.cn/post/6968820138842062879
    enum A {
        A = "A",
        B = "B",
    }

    // C1: 枚举类型兼容了
    const c: CmpA = (ele: A) => {
        switch (ele) {
            case A.A:
                return true;
            default:
                return false;
        }
    };

    logUnderline();
}

export default { use };
